{% extends "sentry/emails/base.html" %}

{% load sentry_avatars %}
{% load sentry_helpers %}
{% load sentry_features %}
{% load i18n static %}

{% block preheader %}
  New alert from {{ project_label }}.
{% endblock %}

{% block header %}
    <a href="{{ link }}" class="btn">View on Sentry</a>
    {{ block.super }}
{% endblock %}

{% block main %}
    <h2 style="margin-bottom: 15px">
        New alert from <a href="{{group.project.get_absolute_url}}">{{ project_label }}</a>
        {% if environment %} in {{ environment }}{% endif %}
    </h2>

    {% if enhanced_privacy %}
      <div class="event">
        <div class="event-id">ID: {{ event.event_id }}</div>
        <div class="event-date">{{ event.datetime|date:"N j, Y, g:i:s a e" }}</div>
      </div>

      <div class="notice">Details about this issue are not shown in this notification since enhanced privacy
        controls are enabled. For more details about this issue, <a href="{{ link }}">view this issue on Sentry</a>.</div>
    {% else %}
      <table class="event-list">
        <tr>
            <th colspan="2">Issue</th>
        </tr>
        <tr>
          <td class="error-level">
              <span class="level level-{{ group.get_level_display }}">{{ group.get_level_display }}</span>
          </td>
          <td class="event-detail">
            <div class="issue">
              {% with type=event.get_event_type metadata=event.get_event_metadata transaction=event.transaction %}
                {% if type == "error" %}
                  <div class="event-type error">
                    <h3>
                      {% if metadata.type %}
                        <a href="{% absolute_uri link %}">{{ metadata.type|truncatechars:40 }}</a>
                        {% if transaction %}
                          <span class="event-subtitle">{{ transaction }}</span>
                        {% endif %}
                        <br />
                        {% if metadata.value %}
                          <small>{{ metadata.value|truncatechars:100|soft_break:40 }}</small>
                        {% endif %}
                      {% else %}
                        <a href="{% absolute_uri link %}">{{ metadata.value|truncatechars:40 }}</a><br />
                        {% if transaction %}
                          <span class="event-subtitle">{{ transaction }}</span>
                        {% endif %}
                      {% endif %}
                    </h3>
                  </div>
                {% elif type == "csp" %}
                  <div class="event-type csp">
                    <h3>
                      <a href="{% absolute_uri link %}">{{ metadata.directive|truncatechars:40 }}</a><br />
                      {% if metadata.uri %}
                        <span class="event-subtitle">{{ metadata.uri }}</span>
                      {% endif %}
                    </h3>
                  </div>
                {% else %}
                  <div class="event-type default">
                    <h3>
                      <a href="{% absolute_uri link %}">{{ event.title|truncatechars:40 }}</a><br />
                      {% if transaction %}
                        <span class="event-subtitle">{{ transaction }}</span>
                      {% endif %}
                    </h3>
                  </div>
                {% endif %}
              {% endwith %}
            </div>
          </td>
        </tr>
      </table>

      <div class="event">
        <div class="event-id">ID: {{ event.event_id }}</div>
        <div class="event-date">{{ event.datetime|date:"N j, Y, g:i:s a e" }}</div>
      </div>

      {% if commits %}
      <div class="committers">
        <h3 class="title" style="margin-bottom: 10px">Suspect Commits</h3>
        <table class="table commit-table">
        {% for commit in commits %}
          <tr>
            <td style="padding:0;width:32px;">{% email_avatar commits.author.name commits.author.email 32 %}</td>
            <td>
              <h5 class="truncate">{{ commit.subject }}</h5>
              <div><small>{{ commit.shortId }}&nbsp;&mdash;&nbsp;
                {% if commit.author %}
                  <strong>{{ commit.author.name }}</strong>
                {% else %}
                  <strong>Unknown Author</strong>
                {% endif %}
              </small></div>
            </td>
          </tr>
        {% endfor %}
        </table>
      </div>
      {% endif %}

      {% for label, html, _ in interfaces %}
      <div class="interface">
          <h3 class="title">{{ label }}</h3>
          {{ html }}
      </div>
      {% endfor %}

      {% if tags %}
        <h3>Tags</h3>

        <ul class="tag-list">
        {% for tag_key, tag_value in tags %}
          <li>
              <strong>{{ tag_key|as_tag_alias }}</strong>
              <em>=</em>
              <span>
              {% with query=tag_key|as_tag_alias|add:":\""|add:tag_value|add:"\""|urlencode %}
                <a href="{% absolute_uri '/organizations/{}/issues/' group.project.organization.slug %}?project={{ group.project.id }}&query={{ query }}">{{ tag_value|truncatechars:50 }}</a> {% if tag_value|is_url %}<a href="{{ tag_value }}" class="icon-share"></a>{% endif %}
              {% endwith %}
              </span>
          </li>
        {% endfor %}
        </ul>
      {% endif %}
    {% endif %}

    {% if rules %}
        <p class="via">
            You are receiving this email due to matching rules:
            {% for rule_label, rule_link in rules %}
                <a href="{% absolute_uri rule_link %}">{{ rule_label }}</a>{% if not forloop.last %}, {% endif %}
            {% endfor %}
        </p>
    {% endif %}

    {% if not has_integrations %}
        <div class="logo-container">
            <img src="{% static 'sentry/images/logos/logo-slack.svg' %}" class="logo" alt="Slack"/>
            <img src="{% static 'sentry/images/logos/logo-pagerduty.svg' %}" class="logo" alt="PagerDuty"/>
            <img src="{% static 'sentry/images/logos/logo-msteams.svg' %}" class="logo" alt="MS Teams"/>
            <img src="{% static 'sentry/images/logos/logo-opsgenie.svg' %}" class="logo" alt="OpsGenie"/>
            <img src="{% static 'sentry/images/logos/logo-twilio.svg' %}" class="logo" alt="Twilio"/>
            <img src="{% static 'sentry/images/logos/logo-victorops.svg' %}" class="logo" alt="VictorOps"/>
            <img src="{% static 'sentry/images/logos/logo-amixr.svg' %}" class="logo" alt="Amixr"/>
        </div>
        <p class="align-center">
            <a href="{% absolute_uri 'settings/{}/integrations/?referrer=alert_email' group.project.organization.slug %}">{{ "Get this alert wherever you work" }}</a>
        </p>
    {% endif %}

    {# support for gmail actions #}
    <div itemscope itemtype="http://schema.org/EmailMessage">
      <meta itemprop="description" content="View Issue Details in Sentry"/>
      <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
        <link itemprop="url" href="{{ link }}"/>
        <meta itemprop="name" content="View in Sentry"/>
      </div>
      <div itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
        <meta itemprop="name" content="GetSentry"/>
        <link itemprop="url" href="https://sentry.io/"/>
      </div>
    </div>
{% endblock %}
